﻿@using KRM.Core
@model IEnumerable<KRM.Core.vWarehouseStockDetailsForPart>
@{
    Layout = "~/Views/Shared/_PopupLayout.cshtml";
    tblKRMPart part = ViewBag.Part;
    ViewBag.Title = part.PartName + ": " + part.PartID;
    var status = StockTemp.PartIsStocked(part.PartID) ? "STOCKED CONTROLLED" : "NOT STOCK CONTROLLED";
    IEnumerable<tblKRMWarehous> warehouses = ViewBag.Warehouses;
    KRMEntities db = ViewBag.db;
    IEnumerable<vWebStockHistory> stockHistories = ViewBag.StockHistories;
}
<script src="/js/stockcontrol.js"></script>
<div style="padding: 10px">
    <p>Stock Status: <strong>@status</strong></p>
    <div class="row-fluid">
        <div class="span2">Reorder Level</div>
        <div class="span2">
            <input class="input-block-level" type="text" id="reorder" value="@StockTemp.GetReorderLevel(part.PartID)"/>
        </div>
        <div class="span2">
                            <a href="#stochistory" role="button" data-toggle="modal" class="btn btn-primary">Stock History</a>
                        </div>

    </div>
    <div class="rdm-scroll height200 overflow-auto">
        <table class="table table-bordered table-fix">
            <thead>
                <tr>
                    <th>PartID</th>
                    <th>WarehouseID</th>
                    <th>WarehouseName</th>
                    <th>FreeStock</th>
                    <th>AllocatedStock</th>
                    <th>PickedNotLoadedStock</th>
                    <th>ShippingPriority</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in Model)
                {
                    <tr>
                        <td>@item.PartID</td>
                        <td>@item.WarehouseID</td>
                        <td>@item.WarehouseName</td>
                        <td>@item.FreeStock</td>
                        <td>@item.AllocatedStock</td>
                        <td>@item.PickedNotLoadedStock</td>
                        <td>@item.ShippingPriority</td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <ul class="tabs tabs-inline tabs-top orderdetail-task-tabs">
        <li class="active">
            <a href="#addstock" data-toggle="tab">Add Stock</a>
        </li>
        <li>
            <a href="#reducestock" data-toggle="tab">Reduce Stock</a>
        </li>
        <li>
            <a href="#transferstock" data-toggle="tab">Transfer Stock</a>
        </li>
        <li>
            <a href="#shippingpriority" data-toggle="tab">Shipping Priority</a>
        </li>
    </ul>

    <div class="tab-content padding tab-content-inline tab-content-bottom orderdetail-task-tabs-content">
        <div class="tab-pane active tabstockcontent" id="addstock">
            <form action="/stockcontrol/addstock" method="POST" class="margin0" id="fr-addstock">
                <input type="hidden" name="partid" value="@part.PartID"/>
                <p>Please fill in the details below to add stock. Remember the Qty is the number of items you are increasing the stock by:</p>
                <div class="row-fluid" style="margin:30px 0">
                    <div class="span2">Quantity to Add:</div>
                    <div class="span3">
                        <input type="text" name="qty" class="input-block-level" required="required" id="qty" />
                    </div>
                    <div class="span2 text-right">Warehouse</div>
                    <div class="span3">
                        @Html.DropDownList("WarehouseID", null, new { @class = "input-block-level" })
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">
                        Reason
                    </div>
                    <div class="span8">
                        <input type="text" class="input-block-level" name="reason" required="required" />
                    </div>
                    <div class="span2">
                        <input type="submit" class="btn btn-primary" value="Add Stock" style="width: 100%" />
                    </div>
                </div>
            </form>
        </div>
        <div class="tab-pane tabstockcontent" id="reducestock">
            <form action="/stockcontrol/reducestock" method="POST" class="margin0" id="fr-reducestock">
                <input type="hidden" name="partid" value="@part.PartID"/>
                <p>Please fill in the details below to reduce stock. Remember the Qty is the number of items you are reducing the stock by:</p>
                <div class="row-fluid" style="margin:30px 0">
                    <div class="span2">Qty to Reduce:</div>
                    <div class="span3">
                        <input type="text" name="qty" class="input-block-level" required="required" id="qtyreduce" />
                    </div>
                    <div class="span2 text-right">Warehouse</div>
                    <div class="span3">
                        @Html.DropDownList("WarehouseID", null, new { @class = "input-block-level" })
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">
                        Reason
                    </div>
                    <div class="span8">
                        <input type="text" class="input-block-level" name="reason" required="required" />
                    </div>
                    <div class="span2">
                        <input type="submit" class="btn btn-primary" value="Reduce Stock" style="width: 100%" />
                    </div>
                </div>
            </form>
        </div>
        <div class="tab-pane tabstockcontent" id="transferstock">
            <form action="/stockcontrol/transferstock" method="POST" class="margin0" id="fr-transferstock">
                <input type="hidden" name="partid" value="@part.PartID"/>
                <p>Please fill in the details below to transfer stock. Remember the Qty is the number of items you are transfering the stock to another warehouse :</p>
                <div class="row-fluid">
                    <div class="span2">Qty to Transfer:</div>
                    <div class="span3">
                        <input type="text" name="qty" class="input-block-level" required="required" id="qtytransfer" />
                    </div>
                    <div class="span2 text-right">From Warehouse</div>
                    <div class="span3">
                        @Html.DropDownList("WarehouseID", null, new { @class = "input-block-level" })
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span5"></div>
                    <div class="span2 text-right">To Warehouse</div>
                    <div class="span3">
                        @Html.DropDownList("ToWarehouseID", null, new { @class = "input-block-level" })
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span2">
                        Reason
                    </div>
                    <div class="span8">
                        <input type="text" class="input-block-level" name="reason" required="required" />
                    </div>
                    <div class="span2">
                        <input type="submit" class="btn btn-primary" value="Transfer Stock" style="width: 100%" />
                    </div>
                </div>
            </form>
        </div>
        <div class="tab-pane tabstockcontent" id="shippingpriority">
            <form action="/stockcontrol/shippingpriority" method="POST" class="margin0" id="fr-shippingpriority">
                <input type="hidden" name="partid" value="@part.PartID"/>
                <div class="row-fluid">
                    <div class="span1"></div>
                    <div class="span10" style="background: #E7E7E7;">
                        <div style="padding: 10px">
                            @foreach (var item in warehouses)
                            {
                                var stockLevel = db.KRMSTKSP_getPartLevelsInWarehouses(part.PartID).FirstOrDefault(a => a.WarehouseID == item.WarehouseID);
                                <input type="hidden" name="warehouseids" value="@(item.WarehouseID)_@(stockLevel != null ? stockLevel.PriorityOrder : 0)" />
                                <div class="row-fluid">
                                    <div class="span3">@item.WarehouseName</div>
                                    <div class="span2">Stock Level</div>
                                    <div class="span2">
                                        <input type="text" class="input-block-level" value="@(stockLevel != null ? stockLevel.StockLevel : 0)" readonly="readonly" name="stocklevels"/></div>
                                    <div class="span3 text-right">Shipping Priority</div>
                                    <div class="span2">
                                        <input type="text" class="input-block-level" value="@(stockLevel != null ? stockLevel.PriorityOrder : 0)" name="priorities" />
                                    </div>
                                </div>
                            }
                        </div>
                    </div>
                    <div class="span1"></div>
                </div>
                <div class="row-fluid" style="margin-top: 10px">
                    <div class="span1"></div>
                    <div class="span1">Reason</div>
                    <div class="span7">
                        <input type="text" class="input-block-level" name="reason" required="required" />
                    </div>
                    <div class="span2">
                        <input type="submit" class="btn btn-primary" value="Save" style="width: 100%" />
                    </div>
                    <div class="span1"></div>
                </div>
            </form>
        </div>
    </div>
</div>
<div id="stochistory" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="stochistory" aria-hidden="true" data-width="700">
    <div class="modal-body">
        <table class="table table-fix table-bordered">
            <thead>
                <tr>
                    <th>Date Of Change</th>
                    <th>KRM Login</th>
                    <th>Win Login</th>
                    <th>WareHouseName</th>
                    <th>StartStock</th>
                    <th>EndStock</th>
                    <th>StartPriority</th>
                    <th>EndPriority</th>
                    <th>Reason</th>
                </tr>
            </thead>
            <tbody>
                @foreach (var item in stockHistories)
                {
                    <tr>
                        <td>@item.Date_of_Change</td>
                        <td>@item.KRM_Login</td>
                        <td>@item.Win_Login</td>
                        <td>@item.WarehouseName</td>
                        <td>@item.StartStock</td>
                        <td>@item.EndStock</td>
                        <td>@item.StartPriority</td>
                        <td>@item.EndPriority</td>
                        <td>@item.Reason</td>
                    </tr>
                }
            </tbody>
        </table>
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    </div>
</div>